//pc http://47.108.153.85:8082/

global.WXWEBURI = codeurl //微信签名登录
let baseURI = apiurl
import axios from "axios"
import store from "./store/index"


const service = axios.create({
    baseURL: baseURI,
    
    timeout: 6000
})


service.interceptors.request.use(
    config => {
        let loginInfo = JSON.parse(sessionStorage.getItem("loginInfo"))
        let { token, tokenKey } = loginInfo ?? {}
        if (token) {
            config.headers['Authorization'] = token;
            config.headers['Authorization-key'] = tokenKey;
        }
        return config;
    },
    error => {
        // do something with request error
        console.log(error); // for debug
        return Promise.reject(error);
    }
);

// response interceptor
service.interceptors.response.use(
    response => {
        const res = response.data;

        if (typeof res != "object") {
            return res;
        }
        if (res.code == 200) {
            return res;
        } else {
            return Promise.reject(new Error(res.msg || 'Error'));
        }
    },
    error => {
        return Promise.reject(error);
    }
);



export default service
